package com.pd.backend.service.impl;

import com.pd.backend.entity.ScheduleJobLog;
import com.pd.backend.dao.ScheduleJobLogDao;
import com.pd.backend.service.ScheduleJobLogService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 定时任务日志(ScheduleJobLog)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:39
 */
@Service("scheduleJobLogService")
public class ScheduleJobLogServiceImpl implements ScheduleJobLogService {
    @Resource
    private ScheduleJobLogDao scheduleJobLogDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ScheduleJobLog queryById(Long id) {
        return this.scheduleJobLogDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param scheduleJobLog 筛选条件
     * @param pageRequest    分页对象
     * @return 查询结果
     */
    @Override
    public Page<ScheduleJobLog> queryByPage(ScheduleJobLog scheduleJobLog, PageRequest pageRequest) {
        long total = this.scheduleJobLogDao.count(scheduleJobLog);
        return new PageImpl<>(this.scheduleJobLogDao.queryAllByLimit(scheduleJobLog, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param scheduleJobLog 实例对象
     * @return 实例对象
     */
    @Override
    public ScheduleJobLog insert(ScheduleJobLog scheduleJobLog) {
        this.scheduleJobLogDao.insert(scheduleJobLog);
        return scheduleJobLog;
    }

    /**
     * 修改数据
     *
     * @param scheduleJobLog 实例对象
     * @return 实例对象
     */
    @Override
    public ScheduleJobLog update(ScheduleJobLog scheduleJobLog) {
        this.scheduleJobLogDao.update(scheduleJobLog);
        return this.queryById(scheduleJobLog.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.scheduleJobLogDao.deleteById(id) > 0;
    }
}
